#!/usr/bin/env perl
use strict;
use warnings;
=pod
@描述：
	1.计算9大车型 dbhome searchterm newenerge的pv uv 跳出pv 跳出uv值
	2.这里使用perl就是看中perl在正则匹配上的方便
@作者：范洪星
@日期：2014年4月11日 星期五 上午
=cut

my %hash;

sub insertHash{
	my ($key,$pv,$suv) = @_;
	my @cols = ();
	if(exists($hash{$key})){
		@cols = split(/\t/,$hash{$key});
		$cols[0] += $pv;
		if($cols[1] !~ $suv){
			$cols[1] = $cols[1].",".$suv;
		}
	} else{
		$cols[0] = $pv;
		$cols[1] = $suv;
	}
	$hash{$key} = $cols[0]."\t".$cols[1];
}


while(my $line = <>) {
	chomp($line);
	my @cols = split(/\t/,$line);
	
	my $suv = $cols[3];
	my $domain = $cols[4];
	my $url = $cols[5];
	my $refer = $cols[8];
	my $whole = $domain.$url;
	#--分成pvuv计算和go_pvuv计算--#
	#开始pvuv类计算
	if($domain eq "auto.sohu.com"){
		if($url eq "/newenerge/"){
			#printf("newenerge_pvuv\t%s\t%s\n",1,$suv);
			insertHash("newenerge_pvuv",1,$suv);
		}
	} elsif($domain eq "db.auto.sohu.com"){
		if($url =~ /^(\/model-list-|\/index|\/$|$)/){
			#printf("dbhome_pvuv\t%s\t%s\n",1,$suv);
			insertHash("dbhome_pvuv",1,$suv);
			#print($line."\n");
		} elsif($url =~ /\/searchterm.sip/){
			#printf("searchterm_pvuv\t%s\t%s\n",1,$suv);
			insertHash("searchterm_pvuv",1,$suv);
		} elsif($url =~ /\/a00[\.|-]/){
			#printf("a00_pvuv\t%s\t%s\n",1,$suv);
			insertHash("a00_pvuv",1,$suv);			
			insertHash("9_pvuv",1,$suv);			
		} elsif($url =~ /\/a0[\.|-]/){
			#printf("a0_pvuv\t%s\t%s\n",1,$suv);
			insertHash("a0_pvuv",1,$suv);
			insertHash("9_pvuv",1,$suv);			
		} elsif($url =~ /\/a[\.|-]/){
			#printf("a_pvuv\t%s\t%s\n",1,$suv);
			insertHash("a_pvuv",1,$suv);
			insertHash("9_pvuv",1,$suv);			
		} elsif($url =~ /\/b[\.|-]/){
			#printf("b_pvuv\t%s\t%s\n",1,$suv);
			insertHash("b_pvuv",1,$suv);
			insertHash("9_pvuv",1,$suv);			
		} elsif($url =~ /\/c[\.|-]/){
			#printf("c_pvuv\t%s\t%s\n",1,$suv);
			insertHash("c_pvuv",1,$suv);
			insertHash("9_pvuv",1,$suv);			
		} elsif($url =~ /\/luxury[\.|-]/){
			#printf("luxury_pvuv\t%s\t%s\n",1,$suv);
			insertHash("luxury_pvuv",1,$suv);
			insertHash("9_pvuv",1,$suv);			
		} elsif($url =~ /\/mpv[\.|-]/){
			#printf("mpv_pvuv\t%s\t%s\n",1,$suv);
			insertHash("mpv_pvuv",1,$suv);
			insertHash("9_pvuv",1,$suv);			
		} elsif($url =~ /\/suv[\.|-]/){
			#printf("suv_pvuv\t%s\t%s\n",1,$suv);
			insertHash("suv_pvuv",1,$suv);
			insertHash("9_pvuv",1,$suv);			
		} elsif($url =~ /\/sportscars[\.|-]/){
			#printf("sportscars_pvuv\t%s\t%s\n",1,$suv);
			insertHash("sportscars_pvuv",1,$suv);
			insertHash("9_pvuv",1,$suv);			
		}
	}
	#开始计算go_pvuv
	if($refer =~ /auto.sohu.com\/newenerge/ && $whole !~ /auto.sohu.com\/newenerge/){
		#printf("newenerge_go\t%s\t%s\n",1,$suv);
		insertHash("newenerge_go",1,$suv);
	} elsif($refer =~ /db.auto.sohu.com\/searchterm.sip/ && $whole !~ /db.auto.sohu.com\/searchterm.sip/){
		#printf("searchterm_go\t%s\t%s\n",1,$suv);
		insertHash("searchterm_go",1,$suv);
	} elsif($refer =~ /db.auto.sohu.com(\/model-list-|\/index|\/$|$)/ && $whole !~ /db.auto.sohu.com(\/model-list-|\/index|\/$|$)/){
		#printf("%s\t%s\n",$refer,$whole);
		#printf("dbhome_go\t%s\t%s\n",1,$suv);
		insertHash("dbhome_go",1,$suv);
	} elsif($refer =~ /db.auto.sohu.com\/a00[\.|-]/ && $whole !~ /db.auto.sohu.com\/a00[\.|-]/){
		#printf("a00_go\t%s\t%s\n",1,$suv);
		insertHash("a00_go",1,$suv);
		insertHash("9_go",1,$suv);
	} elsif($refer =~ /db.auto.sohu.com\/a0[\.|-]/ && $whole !~ /db.auto.sohu.com\/a0[\.|-]/){
		#printf("a0_go\t%s\t%s\n",1,$suv);
		insertHash("a0_go",1,$suv);
		insertHash("9_go",1,$suv);
	} elsif($refer =~ /db.auto.sohu.com\/a[\.|-]/ && $whole !~ /db.auto.sohu.com\/a[\.|-]/){
		#printf("a_go\t%s\t%s\n",1,$suv);
		insertHash("a_go",1,$suv);
		insertHash("9_go",1,$suv);
	} elsif($refer =~ /db.auto.sohu.com\/b[\.|-]/ && $whole !~ /db.auto.sohu.com\/b[\.|-]/){
		#printf("b_go\t%s\t%s\n",1,$suv);
		insertHash("b_go",1,$suv);
		insertHash("9_go",1,$suv);
	} elsif($refer =~ /db.auto.sohu.com\/c[\.|-]/ && $whole !~ /db.auto.sohu.com\/c[\.|-]/){
		#printf("c_go\t%s\t%s\n",1,$suv);
		insertHash("c_go",1,$suv);
		insertHash("9_go",1,$suv);
	} elsif($refer =~ /db.auto.sohu.com\/luxury[\.|-]/ && $whole !~ /db.auto.sohu.com\/luxury[\.|-]/){
		#printf("luxury_go\t%s\t%s\n",1,$suv);
		insertHash("luxury_go",1,$suv);
		insertHash("9_go",1,$suv);
	} elsif($refer =~ /db.auto.sohu.com\/mpv[\.|-]/ && $whole !~ /db.auto.sohu.com\/mpv[\.|-]/){
		#printf("mpv_go\t%s\t%s\n",1,$suv);
		insertHash("mpv_go",1,$suv);
		insertHash("9_go",1,$suv);
	} elsif($refer =~ /db.auto.sohu.com\/suv[\.|-]/ && $whole !~ /db.auto.sohu.com\/suv[\.|-]/){
		#printf("suv_go\t%s\t%s\n",1,$suv);
		insertHash("suv_go",1,$suv);
		insertHash("9_go",1,$suv);
	} elsif($refer =~ /db.auto.sohu.com\/sportscars[\.|-]/ && $whole !~ /db.auto.sohu.com\/sportscars[\.|-]/){
		#printf("sportscars_go\t%s\t%s\n",1,$suv);
		insertHash("sportscars_go",1,$suv);
		insertHash("9_go",1,$suv);
	}
}

while(my($k,$v) = each(%hash)){
	my @cols = split(/\t/,$v);
	printf("%s\t%s\t%s\n",$k,$cols[0],$cols[1]);
}
